﻿using mfLogger;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace mfLogger.Test
{
    
    
    /// <summary>
    ///This is a test class for mfLoggerTest and is intended
    ///to contain all mfLoggerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class mfLoggerTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Debug
        ///</summary>
        [TestMethod()]
        public void DebugTest()
        {
            mfLogger target = mfLogger.Instance;
            target.Messages.Clear();

            target.Level = enumLogMessageLevel.Debug;

            string text = "test debug";

            target.Debug(text);

            Assert.AreEqual(text, target.Messages[0].Text);
        }

        /// <summary>
        ///A test for Error
        ///</summary>
        [TestMethod()]
        public void ErrorTest()
        {
            mfLogger target = mfLogger.Instance;
            target.Messages.Clear();

            Exception ex = new Exception("error"); 

            target.Error(ex);

            Assert.AreEqual("error\r\nStacktrace:\r\n\r\n", target.Messages[0].Text);
        }

        /// <summary>
        ///A test for Error
        ///</summary>
        [TestMethod()]
        public void ErrorTest1()
        {
            mfLogger target = mfLogger.Instance;
            target.Messages.Clear();

            string text = "test error";

            target.Error(text);

            Assert.AreEqual(text, target.Messages[0].Text);
        }

        /// <summary>
        ///A test for HandleMessage
        ///</summary>
        [TestMethod()]
        public void HandleMessageTest()
        {
            mfLogger target = mfLogger.Instance;
            target.Messages.Clear();

            mfLogMessage msg = new mfLogMessage("test"); 

            target.HandleMessage(msg);

            Assert.AreEqual(msg.Text, target.Messages[0].Text);
        }

        /// <summary>
        ///A test for Log
        ///</summary>
        [TestMethod()]
        public void LogTest()
        {
            mfLogger target = mfLogger.Instance;
            mfLogMessage msg = new mfLogMessage("test");

            target.Log(msg);

            Assert.AreEqual(msg.Text, target.Messages[0].Text);
        }

        /// <summary>
        ///A test for Warning
        ///</summary>
        [TestMethod()]
        public void WarningTest()
        {
            mfLogger target = mfLogger.Instance;

            string text = "warning"; 

            target.Warning(text);

            Assert.AreEqual(text, target.Messages[0].Text);
        }

        /// <summary>
        ///A test for Appenders
        ///</summary>
        [TestMethod()]
        [DeploymentItem("mfLogger.dll")]
        public void AppendersTest()
        {
            mfLogger target = mfLogger.Instance;

            mfDebugAppender expected = new mfDebugAppender("DebugAppender");
            ILoggerAppender actual;

            target.Appenders.Add(expected);
            actual = target.Appenders[0];

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Instance
        ///</summary>
        [TestMethod()]
        public void InstanceTest()
        {
            mfLogger actual;
            actual = mfLogger.Instance;

            Assert.AreNotEqual(null, actual);
        }

        /// <summary>
        ///A test for IsEnabled
        ///</summary>
        [TestMethod()]
        public void IsEnabledTest()
        {
            mfLogger target = mfLogger.Instance;

            bool expected = true; 
            bool actual;

            target.IsEnabled = expected;
            actual = target.IsEnabled;

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Level
        ///</summary>
        [TestMethod()]
        public void LevelTest()
        {
            mfLogger target = mfLogger.Instance;

            enumLogMessageLevel expected = enumLogMessageLevel.Warning; 
            enumLogMessageLevel actual;

            target.Level = expected;
            actual = target.Level;

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Name
        ///</summary>
        [TestMethod()]
        public void NameTest()
        {
            mfLogger_Accessor target = new mfLogger_Accessor(); 
            string expected = "appname"; 
            string actual;

            target.Name = expected;
            actual = target.Name;

            Assert.AreEqual(expected, actual);
        }
    }
}
